import { Injectable } from '@angular/core';
import { RequestService } from '../../../cores/services';
import { ApiData } from '../../../cores/classes';
import { Observable } from 'rxjs';
import { SearchParams } from '../../../cores/classes/search-params';
import { AddOrder, Goods, GoodsSpecification, GoodsSpecificationDetail } from '../interfaces/purchase.interface';
import { Pagination } from 'ng-tui';
@Injectable()
export class PurchaseService {

    constructor(
        private request: RequestService,

    ) { }

    /**
     * order查询商品，分页
     */
    searchGoods(pagination: Pagination, search: SearchParams): Observable<ApiData> {
        return this.request.get('/managerapi/purchase/order/search', pagination.getpageDataWith(search.values));
    }
    /**
* order查询商品详情
*/
    getDetail(id: number): Observable<ApiData> {
        return this.request.get('/managerapi/purchase/order/get', { id });
    }
    /**
    * 添加商品
    */
    insertGoods(addOrder: any): Observable<ApiData> {
        return this.request.post('/managerapi/purchase/order/add', addOrder);
    }
    /**
  * 修改商品
  */
    updateGoods(addOrder: any): Observable<ApiData> {
        return this.request.put('/managerapi/purchase/order/update', addOrder);
    }
    /**
  * 供应商下拉选择
  */
    supplierList(): Observable<ApiData> {
        return this.request.get('/managerapi/supplier/get', {});
    }
    /**
* 人员下拉选择
*/
    peopleList(): Observable<ApiData> {
        return this.request.get('/managerapi/staff/get', {});
    }
    /**
* 仓库下拉选择
*/
    warehouse(): Observable<ApiData> {
        return this.request.get('/managerapi/warehouse/get', {});
    }
    /**
* 区域下拉选择
*/
    areaList(): Observable<ApiData> {
        return this.request.get('/managerapi/area/get', {});
    }




    /**
     * 删除商品
     */
    deleteGoods(goodsId: number): Observable<ApiData> {
        return this.request.delete('/store/goods/delete', { goodsId });
    }

    /**
     * 获取指定商品
     */
    getGoods(goodsId: number): Observable<ApiData> {
        return this.request.get('/store/goods/get', { goodsId });
    }

    /**
     * 更新商品规格
     */
    updateGoodsSpecification(
        goodsId: number,
        goodsSpecifications: GoodsSpecification[],
        goodsSpecificationDetails: GoodsSpecificationDetail[]
    ): Observable<ApiData> {
        return this.request.put('/store/goods/specification/update', { goodsId, goodsSpecifications, goodsSpecificationDetails });
    }

    /**
     * 获取商品下拉选项
     */
    getGoodsTypeOptions(): Observable<ApiData> {
        return this.request.url('/store/goods/type/options');
    }

    /**
     * 上传商品图片
     */
    uploadGoodsImage(file: File): Observable<string> {
        return this.request.ossUpload('/store/goods/image/access', file);
    }

    // getManagerInfo(): Observable<ApiData> {
    //     return this.request.url('/managerapi/info');
    // }

    // updateManagerInfo(manager: Manager): Observable<ApiData> {
    //     return this.request.put('/managerapi/update', manager);
    // }

    // uplodaAvatar(file: File): Observable<string> {
    //     return this.request.ossUpload('/managerapi/avatar/access', file);
    // }
}
